<?php 

require_once(APPPATH.'controllers/epicentr.php');

class YourCompany extends Epicentr {

	public function YourCompany() {
		parent::Epicentr();
		
		$this->view_data['maintab'] = '';
		
		$this->view_data['page_js'][] = 'jquery.inplace';
		$this->view_data['page_js'][] = 'companies_inplace';
		
		if ($this->authentication->getProfileType() == 'admin') {
			$this->permissions->editcompany = true;
		} else {
			$this->permissions->editcompany = false;
		}
		
	}
	
	public function index() {
		$this->load->model('companiesmodel');
		$this->load->model('costcentermodel');
		$this->load->model('usersmodel');
		$this->load->model('jobsmodel');
		
		$departments = $this->costcentermodel->getAllCenters();
		
		$mycompany = $this->companiesmodel->getMyCompany();
		
		if ($departments) {
			foreach ($departments as $key => $department) {
				$departments[$key]->users = $this->usersmodel->find(array('deleted' => 0, 'costcenterid' => $department->id));
				$departments[$key]->jobs = $this->jobsmodel->getJobsByDepartment($department->id);
			}
		}
		$this->view_data['mycompany'] = $mycompany;
		$this->view_data['departments'] = $departments;
		
		$this->layout->buildPage('admin/main', $this->view_data);
    }
        
}
?>